﻿using Microsoft.Cloud.API.AzurePack.Services;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;

namespace Microsoft.Cloud.API.AzurePack.Controllers
{
    public class UsersController : ApiController
    {
        /// <summary>
        /// Retrieves a set of users
        /// </summary>
        /// <returns></returns>
        [Route("api/admin/Users")]
        public async Task<HttpResponseMessage> GetUsers()
        {
            var token = AuthService.Instance.PerformADFSAuth();

            using (var adminService = new WAPAdminService(token))
            {
                var response = await adminService.GetAsync(RelativePaths.Users_List);

                return response;
            }
        }

        /// <summary>
        /// Retrieves a user
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        [Route("api/admin/Users/{userName}")]
        public async Task<HttpResponseMessage> GetUser(string userName)
        {
            var token = AuthService.Instance.PerformADFSAuth();

            using (var adminService = new WAPAdminService(token))
            {
                var response = await adminService.GetAsync(string.Format(RelativePaths.Users_Get, userName));

                return response;
            }
        }
    }
}
